import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:injectable/injectable.dart';

@singleton
class FileLogger {
  late File _logFile;

  FileLogger() {
    _init();
  }

  Future<void> _init() async {
    final directory = await getApplicationDocumentsDirectory();
    _logFile = File('${directory.path}/app.log');
  }

  Future<void> log(String message) async {
    final timestamp = DateTime.now().toIso8601String();
    await _logFile.writeAsString('$timestamp: $message\n', mode: FileMode.append);
  }
}